package com.example.bms.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.ExamManage;
import com.example.bms.mapper.ExamManageMapper;
import com.example.bms.service.ExamManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


/**
 * @apiNote 进行试卷的增删改查
 * @author 钟顺浩
 * @email 2918185121@qq.com
 * @since 1.0.0
 */
@Service
public class ExamManageServiceImpl implements ExamManageService {
    @Autowired
    private ExamManageMapper examManageMapper;


    /**
     * @apiNote 不分页查询所有试卷
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return List<ExamManage>
     * @since 1.0.0
     */
    @Override
    public List<ExamManage> findAll() {
        return examManageMapper.findAll();
    }


    /**
     * @apiNote 分页查询所有试卷
     * @author 钟顺浩
     * @param page 页数
     * @email 2918185121@qq.com
     * @return IPage<ExamManage>
     * @since 1.0.0
     */
    @Override
    public IPage<ExamManage> findAll(Page<ExamManage> page) {
        return examManageMapper.findAllPage(page);
    }


    /**
     * @apiNote 根据考试编号查找试卷所有信息
     * @author 钟顺浩
     * @param examCode 考试编号
     * @email 2918185121@qq.com
     * @return ExamManage
     * @since 1.0.0
     */
    @Override
    public ExamManage findById(Integer examCode) {
        return examManageMapper.findById(examCode);
    }


    /**
     * @apiNote 根据考试编号进行删除试卷
     * @author 钟顺浩
     * @param examCode 考试编号
     * @email 2918185121@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Override
    public int delete(Integer examCode) {
        return examManageMapper.delete(examCode);
    }


    /**
     * @apiNote 修改考试信息
     * @author 钟顺浩
     * @param exammanage 考试实体对象
     * @email 2918185121@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Override
    public int update(ExamManage exammanage) {
        return examManageMapper.update(exammanage);
    }


    /**
     * @apiNote 增加一张试卷
     * @author 钟顺浩
     * @param exammanage 考试实体对象
     * @email 2918185121@qq.com
     * @return int类型，插入成功返回1，插入失败返回0
     * @since 1.0.0
     */
    @Override
    public int add(ExamManage exammanage) {
        return examManageMapper.add(exammanage);
    }


    /**
     * @apiNote 查询最后一条记录的paperId,返回给前端达到自增效果
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return ExamManage
     * @since 1.0.0
     */
    @Override
    public ExamManage findOnlyPaperId() {
        return examManageMapper.findOnlyPaperId();
    }
}
